/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Javabeans;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Muhammed
 * 
 */
public class DataSet implements Cloneable{
    private ArrayList<Attribute> attributes;
    private ArrayList<DatPoint> dataPoints;
    private int outputIndex;
    public DataSet(){
        attributes=new ArrayList<Attribute>();
        dataPoints=new ArrayList<DatPoint>();
    }

    /**
     * @return the attributes
     */
    public ArrayList<Attribute> getAttributes() {
        return attributes;
    }

    /**
     * @param attributes the attributes to set
     */
    public void setAttributes(ArrayList<Attribute> attributes) {
        this.attributes = attributes;
    }

    /**
     * @return the dataPoints
     */
    public ArrayList<DatPoint> getDataPoints() {
        return dataPoints;
    }

    /**
     * @param dataPoints the dataPoints to set
     */
    public void setDataPoints(ArrayList<DatPoint> dataPoints) {
        this.dataPoints = dataPoints;
    }

    public Object clone(){
        try{
            DataSet cloned = (DataSet)super.clone();

            //clone all attributes
            ArrayList<Attribute> tempAtt = new ArrayList<Attribute>();
            Iterator it = attributes.iterator();
            while(it.hasNext()){
                Attribute att = (Attribute) it.next();
                tempAtt.add(att);
            }
            cloned.setAttributes(tempAtt);

            //clone all datapoints
            ArrayList<DatPoint> tempData = new ArrayList<DatPoint>();
            it = dataPoints.iterator();
            while(it.hasNext()){
                DatPoint dp = (DatPoint) it.next();
                tempData.add((DatPoint) dp.clone());
            }
            cloned.setDataPoints(tempData);

            cloned.setOutputIndex(outputIndex);
            return cloned;
        }catch(CloneNotSupportedException e){
            System.out.println(e);
            return null;
        }
    }

    public int size(){
        return dataPoints.size();
    }

    public DatPoint getDataPoint(int index){
        if(index<dataPoints.size())
            return dataPoints.get(index);
        return null;
    }

    public void remove(int index){
        if (index<dataPoints.size())
            dataPoints.remove(index);
    }
    public void remove(DatPoint data){
        dataPoints.remove(data);
    }
    public void add(DatPoint data){
        this.dataPoints.add(data);
    }

    /**
     * @return the outputIndex
     */
    public int getOutputIndex() {
        return outputIndex;
    }

    /**
     * @param outputIndex the outputIndex to set
     */
    public void setOutputIndex(int outputIndex) {
        this.outputIndex = outputIndex;
    }

    public void setWeights(double []weights){
        for(int i=0;i<this.attributes.size()-1;i++){
            attributes.get(i).setWeight(weights[i]);
        }
    }

    public double[] getWeights(){
        int size = this.attributes.size()-1;
        double[] weights = new double[size];
        for(int i=0;i<size;i++){
            weights[i]=attributes.get(i).getWeight();
        }
        return weights;
    }
}
